<?php
/*
+ --------------------------------------------------- +
|  Ineo Article Manager - Version 2.x
|  Copyright 2006-2007, Dan Cryer and William McGann
+ --------------------------------------------------- +

Ineo Article Manager is free software; you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as published by
the Free Software Foundation.

Ineo Article Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Ineo; see the file License.txt.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/

/**
* Ineo - Modules - Categories
*  
* This module handles all front-end actions related to articles.
*
* @package		Ineo
* @subpackage   Modules
* @author		Dan Cryer & William McGann
* @copyright	Dan Cryer & William McGann
* @version		1.0.0
*/
class ineo_mod_category
{
    var $ipsclass;
    var $core;
    
    /**
    * Initialize class:
    */
    function module_init()
    {
        $this->lib_cat =& $this->core->load_library('categories');
		$this->core->load_template('categories');
		$this->core->load_template('articles');
    }
    
    /**
    * Generate and display a list of categories:
    */
    function catlist()
	{
		// Use category library to get an array of categories ( with parent 0 ).
		$categories = $this->lib_cat->load_cats_by_parent(0);
						
		$list = '';
		
		$this->core->title .= ' - ' . $this->ipsclass->lang['ineo_categories'];
		
		// Loop & build list:
		foreach( $categories as $cat )
		{
			$cat['info']['category_articles'] = $this->core->libs['categories']->get_article_count($cat);
			$list .= $this->core->templates['categories']->cat_row( $cat['info'] );
		}
		
		// Output list using main template:
		$this->core->out .= $this->core->templates['categories']->cat_index( $list , $this->ipsclass->lang['ineo_categories'] );
	}
	
	/**
	* Display a category:
	*/
	function cat()
	{
		// Get category ID:
	  	$category_id = intval($this->ipsclass->input['id']);
		
		// Load category information:
    	$category = $this->lib_cat->load_category_data( $category_id );
	
		// Load sub-categories:
		$children = $this->lib_cat->load_cats_by_parent($category_id,true);
	    
		// Load page links and articles:
		list($pages,$articles) = $this->lib_cat->load_articles_page($category_id);
		
		// Set up for passing to templates:
		$data = array('info'=>$category,'children'=>$children,'pages'=>$pages,'articles'=>$articles);
		
		// Load output:
		$this->core->out .= $this->core->templates['categories']->show_category($data);
		
		// Set browser title and breadcrumb tree:
		$this->core->title .= ' - ' . $category['category_name'];
		
		// Build nav tree:
		$this->core->libs['categories']->build_nav_tree( $category_id );
	}
}

?>